package org.example.dingtalkintegrationservice.web;

import io.lettuce.core.dynamic.annotation.Param;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.dingtalkintegrationservice.pojo.IdRecord;
import org.example.dingtalkintegrationservice.service.IdRecordService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * @author pc
 */
@CrossOrigin
@RestController
@Slf4j
public class IdRecordController {
    @Resource
    IdRecordService idRecordService;
    @GetMapping("/getId2ById1")
    public ResponseEntity<String> getId2ById1(@Param("id1")String id1){
        log.info(id1);
        String id2=idRecordService.getId2ById1(id1);
        return new ResponseEntity<>(id2, HttpStatus.OK);
    }
    @GetMapping("/getId2ById1AndUserId")
    public ResponseEntity<String> getId2ById1AndUserId(@Param("id1")String id1,@Param("user_id")String userId){
        log.info(id1+"+"+userId);
        String id2=idRecordService.getId2ById1AndUserId(id1,userId);
        return new ResponseEntity<>(id2, HttpStatus.OK);
    }
    @PostMapping("/saveIdRecord")
    public ResponseEntity<String> saveIdRecordBatch(@RequestBody List<IdRecord> idRecordList){
        idRecordService.insertIdRecordBatch(idRecordList);
        return new ResponseEntity<>(HttpStatus.OK);
    }
    @GetMapping("/getParentById1")
    public ResponseEntity<String> getParentById1(@Param("id1")String id1){
        log.info(id1);
        String id2=idRecordService.getParentById1(id1);
        return new ResponseEntity<>(id2, HttpStatus.OK);
    }
    @GetMapping("/test")
    public String test(@Param("chinese")String chinese){
        log.info(chinese);
        return chinese;
    }
}
